<template>
  <div class="breadcrumb-nav">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item 
        v-for="(item, index) in breadcrumbs" 
        :key="item.key"
        :to="index < breadcrumbs.length - 1 ? item.path : undefined"
        :class="{ 'is-current': index === breadcrumbs.length - 1 }"
      >
        <el-icon v-if="item.icon" class="breadcrumb-icon">
          <span v-if="isEmoji(item.icon)" class="emoji-icon">{{ item.icon }}</span>
          <component v-else :is="getDefaultIcon(item.key)" />
        </el-icon>
        <span class="breadcrumb-text">{{ item.label }}</span>
      </el-breadcrumb-item>
    </el-breadcrumb>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { useMenuStore } from '@/stores/menuStore'
import {
  House,
  ChatDotRound,
  Folder,
  User,
  Document,
  Setting,
  Phone,
  Menu,
  DocumentCopy,
  Calendar,
  Users,
  ScaleToOriginal,
  OfficeBuilding,
  Tools,
  Lock,
  UserFilled
} from '@element-plus/icons-vue'

const route = useRoute()
const menuStore = useMenuStore()

// 图标映射
const iconMap = {
  home: House,
  consultation: ChatDotRound,
  'case-management': Folder,
  'case-list': DocumentCopy,
  'case-create': Document,
  'case-analysis': Document,
  'lawyer-services': User,
  'lawyer-team': Users,
  'lawyer-center': ScaleToOriginal,
  appointment: Calendar,
  resources: Document,
  'legal-resource': Document,
  'legal-news': Document,
  'legal-templates': DocumentCopy,
  system: Setting,
  'user-management': UserFilled,
  'role-management': Lock,
  'system-settings': Tools,
  contact: Phone
}

// 获取默认图标
const getDefaultIcon = (key) => {
  return iconMap[key] || Menu
}

// 判断是否为emoji图标
const isEmoji = (icon) => {
  return /[\u{1F600}-\u{1F64F}]|[\u{1F300}-\u{1F5FF}]|[\u{1F680}-\u{1F6FF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]/u.test(icon)
}

// 计算面包屑路径
const breadcrumbs = computed(() => {
  const currentPath = route.path
  return menuStore.breadcrumbs(currentPath)
})
</script>

<style scoped>
.breadcrumb-nav {
  padding: 16px 24px;
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.breadcrumb-nav :deep(.el-breadcrumb) {
  font-size: 14px;
}

.breadcrumb-nav :deep(.el-breadcrumb__item) {
  display: flex;
  align-items: center;
}

.breadcrumb-nav :deep(.el-breadcrumb__inner) {
  display: flex;
  align-items: center;
  color: #606266;
  font-weight: normal;
  transition: color 0.3s ease;
}

.breadcrumb-nav :deep(.el-breadcrumb__inner:hover) {
  color: #409eff;
}

.breadcrumb-nav :deep(.el-breadcrumb__item.is-current .el-breadcrumb__inner) {
  color: #303133;
  font-weight: 600;
}

.breadcrumb-icon {
  margin-right: 4px;
  font-size: 14px;
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emoji-icon {
  font-size: 14px;
  line-height: 1;
}

.breadcrumb-text {
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .breadcrumb-nav {
    padding: 12px 16px;
  }
  
  .breadcrumb-nav :deep(.el-breadcrumb) {
    font-size: 12px;
  }
  
  .breadcrumb-icon {
    font-size: 12px;
    width: 12px;
    height: 12px;
  }
  
  .emoji-icon {
    font-size: 12px;
  }
  
  .breadcrumb-text {
    font-size: 12px;
  }
}
</style> 